<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="author" content="wangbo">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
    </div>

    <script type="text/javascript" src="../js/react.development.js">    </script>
    <script type="text/javascript" src="../js/react-dom.development.js">    </script>
    <script type="text/javascript" src="../js/prop-types.js">    </script>
    <script type="text/javascript" src="../js/babel.min.js">    </script>
    <script type="text/babel">
        class Button extends React.Component {
            constructor(props) {
                super(props);
                this.state = { data: 0 };
                this.setNewNumber = this.setNewNumber.bind(this);
            }

            setNewNumber() {
                this.setState({ data: this.state.data + 1 })
            }
            // 方法在组件卸载及销毁之前直接调用。
            // 方法中不应调用 setState()，因为该组件将永远不会重新渲染。组件实例卸载后，将永远不会再挂载它。
            // 清除定时器
            // 解绑dom事件
            // 清除网络工作
            componentWillUnmount() {
                console.log('Component 将卸载')
            }
            myclick=()=>{
			    ReactDOM.unmountComponentAtNode(document.getElementById("app"))
		    }
            render() {
                return (
                    <div>
                        <button onClick={this.setNewNumber}>声明周期 {this.state.data}</button>
                        <button onClick={this.myclick}>按住我解决一切烦恼</button>
                        <Content myNumber={this.state.data}></Content>
                    </div>
                );
            }
        }
        class Content extends React.Component {
            
            render() {
                return (
                    <div>
                        <h3>{this.props.myNumber}</h3>
                    </div>
                );
            }
        }
        ReactDOM.render(
            <div>
                <Button />
            </div>,
            document.getElementById('app')
        );
    </script>
</body>

</html>